<cfcomponent>
    <cffunction name="getWeekList">
		<cfargument name="year" type="string" required="true">			<cfargument name="year2" type="string" required="true">
		<cfquery name="list" datasource="#Request.DS#" result="result">
			SELECT *,
				WEEKOFYEAR(`cfp_weeks`.`date`) as `week`,
				YEAR(`cfp_weeks`.`date`) as `year`,
				( SELECT min(`cfp_days`.`date`) as `min` FROM `cfp_days` WHERE `cfp_days`.`week_id` = `cfp_weeks`.`id`
				AND `cfp_days`.`user_id` = '#Session.id#' LIMIT 1 ) as `min`,
				( SELECT max(`cfp_days`.`date`) as `max` FROM `cfp_days` WHERE `cfp_days`.`week_id` = `cfp_weeks`.`id`
				AND `cfp_days`.`user_id` = '#Session.id#' LIMIT 1 ) as `max`
			FROM `cfp_weeks`
			WHERE YEARWEEK(`cfp_weeks`.`date`) >= '#year#' AND YEARWEEK(`cfp_weeks`.`date`) <= '#year2#' AND `cfp_weeks`.`user_id` = '#Session.id#'
			ORDER BY YEARWEEK(`cfp_weeks`.`date`) DESC
		</cfquery>
		<cfreturn list >
    </cffunction>

    <cffunction name="getYearList">
		<cfquery name="list" datasource="#Request.DS#" result="result">
			SELECT YEARWEEK(`date`) as `year` FROM `cfp_weeks` WHERE `user_id` = '#Session.id#' GROUP BY MID(YEARWEEK(`date`), 1, 4) ORDER BY MID(YEARWEEK(`date`), 1, 4) DESC
		</cfquery>
		<cfreturn list >
    </cffunction>

    <cffunction name="getEntriesList"> 
	<cfargument name="week_id" type="numeric" required="true">
         <cfquery name="list" datasource="#Request.DS#">
			SELECT `cfp_entries`.`text` as `text`,
				`cfp_entries`.`day_id` as `day_id`,
				`cfp_days`.`date` as `date`,
				`cfp_days`.`school` as `school`,
				`cfp_days`.`id` as `id`
			FROM `cfp_entries`, `cfp_days`
			WHERE `cfp_entries`.`day_id` = `cfp_days`.`id`
				AND `cfp_days`.`week_id` = '#week_id#'
				AND `cfp_days`.`user_id` = '#Session.id#'
				AND `cfp_entries`.`user_id` = '#Session.id#'
			ORDER BY `cfp_days`.`date` ASC, `cfp_entries`.`sort_id` ASC
		 </cfquery>
<cfsavecontent variable="content">
		<cfset lastDate = ""><cfset i = 1><cfset j = 0>
		<cfoutput query="list">
			<cfif list.date neq lastDate>
		         <cfquery name="listcount" datasource="#Request.DS#">
					SELECT count(`cfp_entries`.`id`) as `counted`
					FROM `cfp_entries`
					WHERE `cfp_entries`.`day_id` = '#list.day_id#'
						AND `cfp_entries`.`user_id` = '#Session.id#'
				 </cfquery>
				<cfif i NEQ 0>
					</ul></td>
					</tr>
				</cfif>
				<cfif j+listcount.counted GT 38 >
					</table>
					<div style="page-break-after: always;"></div>
					<table cellspacing="2" bgcolor="black" width="100%">
					<cfset j = listcount.counted >
				<cfelse>
					<cfset j = j+listcount.counted>
				</cfif>
				<cfset lastDate = list.date>
				<tr>
					<td bgcolor="##D0D0D0" style="text-align: center; padding: 0px;"><img src="http://localhost/cfprotocol/data/wochentage/#LCase(Left(DayOfWeekAsString(DayOfWeek(list.date)), 2))#.jpg"></td>
					<td valign="top" bgcolor="white" width="100%"><cfif list.school EQ 1><small style="float: right; font-weight: bold;">(Berufsschultag) </small></cfif><ul style="margin: 15px;">
			</cfif>
			<cfset i = i+1 >
			<li>#list.text#</li>
		</cfoutput>
		<cfif i NEQ 0>
			</ul></td>
			</tr>
		</cfif>
</cfsavecontent>
		<cfreturn content >
    </cffunction>
</cfcomponent>